package svc.elib.lookup;

import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;

import svc.elib.db.Author;
import svc.elib.db.Database;
import svc.elib.socnet.EvolutionarySnapshots;
import svc.elib.socnet.Net;
import svc.elib.socnet.SocConstructor;

public class EvolutionaryCorrector extends NameSimilarity {

	private Net[] snaps;
	private int startYear;
		
	public EvolutionaryCorrector(Net net) {
		super();
		EvolutionarySnapshots es = new EvolutionarySnapshots(net);
		snaps = es.getSnapshots();
		startYear = es.getStartYear();  
	}
	
	public void similarNames(int year) {
		Net net = snaps[year - startYear];
		
		LinkedList<String> names = new LinkedList<String>();
		Iterator<Author> ait = net.getGraph().getVertices().iterator();
		while (ait.hasNext()) {
			String name = ait.next().getName();
			names.add(name);
		}
		
		checkSimilar(names);
		dumpResults();
	}
	
	public static void main(String[] args) 
		throws IOException
	{
		Database db = new Database("eLibData.csv", 1932, 2011);
		System.out.println(db.info());
		SocConstructor soc = new SocConstructor(db);
		Net net = soc.getNet();
		EvolutionaryCorrector ec = new EvolutionaryCorrector(net);
		ec.similarNames(2011);
	}
}
